package CookieUtils

import (
	"net/http"
)

func AddCookie(w http.ResponseWriter,cookiename string,cookievalue string){
	var cookie = http.Cookie{
		Name:cookiename,
		Value:cookievalue,
		Path:"/",
		MaxAge:60*60 }
	http.SetCookie(w,&cookie)
}

func GetCookie(req http.Request,cookiename string)(*http.Cookie){
	cookie, err := req.Cookie(cookiename)
	if(err==nil){
		return cookie
	}
	return nil
}

func GetCookieValue(req http.Request,cookiename string)(string){
	cookie, err := req.Cookie(cookiename)
	if(err==nil){
		return cookie.Value
	}
	return ""
}

func DeleteCookie(w http.ResponseWriter,cookiename string,cookievalue string){
	var cookie = http.Cookie{
		Name:cookiename,
		Value:cookievalue,
		Path:"/",
		MaxAge:-1 }
	http.SetCookie(w,&cookie)
}